import 'package:car_map/mode/spuare_type_mode.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

import 'load_image.dart';

///轮播图
class WidgetSwiper extends StatefulWidget {
  final List sumspuareList;

  const WidgetSwiper({Key key, this.sumspuareList}) : super(key: key);



  @override
  _widgetSwiperState createState() => _widgetSwiperState();
}

class _widgetSwiperState extends State<WidgetSwiper> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  Container(
      color: Colors.white,
      width: ScreenUtil().setWidth(730),
      height: ScreenUtil().setHeight(180),
      child: Swiper(
        itemCount: 3,
        pagination: new SwiperPagination(),
        autoplay: false,
        itemBuilder: (context, index) {
          return listWidget(widget.sumspuareList[index]);
        },
      ),
    );
  }

  Widget listWidget(List<SpuareTypeModel> modelList) {
    print( modelList.length);
    return ListView.builder(
      itemBuilder: (context, index) {
        return listWidgetItem(modelList[index]);
      },
      itemCount: modelList.length,
      shrinkWrap: true,
      physics: new NeverScrollableScrollPhysics(),
      scrollDirection: Axis.horizontal,
    );
  }

  Widget listWidgetItem(SpuareTypeModel model) {
    return InkWell(
      onTap: () {},
      child: Container(
        color: Colors.white,
        margin: EdgeInsets.only(top: 1.0),
        height: ScreenUtil().setHeight(150.0),
        width: ScreenUtil().setWidth(730/5),
        alignment: Alignment.center,
        padding: EdgeInsets.only(top: 20.0),
        child: Column(
          children: <Widget>[
            LoadAssetImage(
              model.urlPath,
              width: ScreenUtil().setWidth(50.0),
              height: ScreenUtil().setHeight(50.0),
            ),
            Container(
              padding: EdgeInsets.all(5.0),
              child: Text(
                '${model.title}',
                style: TextStyle(fontSize: ScreenUtil().setSp(20.0)),
              ),
            )
          ],
        ),
      ),
    );
  }
}
